﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace Unity.Game.ElisAdvance.ElisScript
{
    //玩家elis引入事件
    public class ElisState_Move
    {

        public static void onFixedProc(ElisActiveObject activeObject, float horiztantlKey)
        {

            if (KeyPressEvent.isKeyPressDownJump())
            {
                activeObject.clearStateVector();
                activeObject.pushStateVector(0);
                activeObject.setState(State.STATE_JUMP);
                return;
            }
            else if (KeyPressEvent.isKeyPressDownAttack())
            {
                activeObject.clearStateVector();
                activeObject.pushStateVector(0);
                activeObject.setState(State.STATE_ATTACK);
                return;
            }
            else if (KeyPressEvent.isKeyPressDownDash())
            {
                activeObject.clearStateVector();
                activeObject.pushStateVector(0);
                activeObject.setState(State.STATE_DASH);

            }

            if (horiztantlKey != 0.0f)
            {
                activeObject.onActiveObjectMoveEvent(horiztantlKey);
            }
           
            if (!KeyPressEvent.isKeyPressLeft() && !KeyPressEvent.isKeyPressRight())
            {
                activeObject.clearStateVector();
                activeObject.setState(State.STATE_STAND);
                return;
            }
        }

        public static void onProc(ElisActiveObject activeObject)
        {

            if (Com.checkObjectTime(activeObject, "GLOBAL_JumpLandTimeEvent", 0.1f) && !activeObject.isLand())
            {
                activeObject.setCurrentPos(
                    Com.getDistancePos(activeObject.getXPos(), activeObject.getDirection(), 0.1f),
                    activeObject.getYPos());

                activeObject.clearStateVector();
                activeObject.pushStateVector(2);
                activeObject.setState(State.STATE_JUMP);
                return;
            }
        }

        public static void onSetState(ElisActiveObject activeObject)
        {
            activeObject.getGravityEvent().setEnable(false);
            activeObject.getAniManager().setAni("Move");
            activeObject.setAngleRotate(0.0f);
            activeObject.setXVelocity(0.0f);
            activeObject.setYVelocity(0.0f);

            activeObject.setCurrentPos(activeObject.getXPos(), activeObject.getYPos() - 0.1f);
        }
    }
}